glcontext: Store the buffer age regions in the GL context
authorBenjamin Otte <otte@redhat.com>
Sun, 8 Apr 2018 22:58:31 +0000 (00:58 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 8 Apr 2018 23:00:31 +0000 (01:00 +0200)
That way, we can store the right region there: The actual painted area
instead of the exposed area (which is way too small).

Also, the GL context is the only user of this data, so storing it there
seems way smarter.

gdk/gdkglcontext.c
gdk/gdkglcontextprivate.h
gdk/gdkinternals.h
gdk/gdksurface.c
gdk/wayland/gdkglcontext-wayland.c
gdk/x11/gdkglcontext-x11.c

index b3703eef34e8a024d975b01c4cf7fb24d690b3f7..07f25aadfbc1283e1853edc2eea097ebced71461 100644 (file)
@@ -133,6 +133,17 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GdkGLContext, gdk_gl_context, GDK_TYPE_DRAW
 
 static GPrivate thread_current_context = G_PRIVATE_INIT (g_object_unref);
 
+static void
+gdk_gl_context_clear_old_updated_area (GdkGLContext *context)
+{
+  int i;
+
+  for (i = 0; i < 2; i++)
+    {
+      g_clear_pointer (&context->old_updated_area[i], cairo_region_destroy);
+    }
+}
+
 static void
 gdk_gl_context_dispose (GObject *gobject)
 {
@@ -140,6 +151,8 @@ gdk_gl_context_dispose (GObject *gobject)
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
   GdkGLContext *current;
 
+  gdk_gl_context_clear_old_updated_area (context);
+
   current = g_private_get (&thread_current_context);
   if (current == context)
     g_private_replace (&thread_current_context, NULL);
@@ -325,6 +338,19 @@ gdk_gl_context_real_end_frame (GdkDrawContext *draw_context,
       gdk_draw_context_end_frame (GDK_DRAW_CONTEXT (shared), painted, damage);
       return;
     }
+
+  if (context->old_updated_area[1])
+    cairo_region_destroy (context->old_updated_area[1]);
+  context->old_updated_area[1] = context->old_updated_area[0];
+  context->old_updated_area[0] = cairo_region_reference (painted);
+}
+
+static void
+gdk_gl_context_surface_resized (GdkDrawContext *draw_context)
+{
+  GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
+
+  gdk_gl_context_clear_old_updated_area (context);
 }
 
 static void
@@ -338,6 +364,7 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
 
   draw_context_class->begin_frame = gdk_gl_context_real_begin_frame;
   draw_context_class->end_frame = gdk_gl_context_real_end_frame;
+  draw_context_class->surface_resized = gdk_gl_context_surface_resized;
 
   /**
    * GdkGLContext:shared-context:
index cf834da3a7fcf7865ed259db381c9c1ea1466ed5..7fe2d008cfc6250bc7699fa1e090777219058984 100644 (file)
@@ -35,6 +35,9 @@ typedef struct _GdkGLContextClass       GdkGLContextClass;
 struct _GdkGLContext
 {
   GdkDrawContext parent_instance;
+
+  /* We store the old drawn areas to support buffer-age optimizations */
+  cairo_region_t *old_updated_area[2];
 };
 
 struct _GdkGLContextClass
index 4a56b91c1d0413780e70706b3d67f9c28f324047..95ac10cb9d58ebb357b548810b2fe75e3622f337 100644 (file)
@@ -177,8 +177,6 @@ struct _GdkSurface
      started. It may be smaller than the expose area if we'e painting
      more than we have to, but it represents the "true" damage. */
   cairo_region_t *active_update_area;
-  /* We store the old expose areas to support buffer-age optimizations */
-  cairo_region_t *old_updated_area[2];
 
   GdkSurfaceState old_state;
   GdkSurfaceState state;
index d9bbcb753424b915fe1a25586cd80d7dc8ab390c..57dd82fab38d4788e3bab5914885467a10333fe9 100644 (file)
@@ -594,31 +594,6 @@ recompute_visible_regions (GdkSurface *private,
                                       recalculate_children);
 }
 
-static void
-gdk_surface_clear_old_updated_area (GdkSurface *surface)
-{
-  int i;
-
-  for (i = 0; i < 2; i++)
-    {
-      if (surface->old_updated_area[i])
-        {
-          cairo_region_destroy (surface->old_updated_area[i]);
-          surface->old_updated_area[i] = NULL;
-        }
-    }
-}
-
-static void
-gdk_surface_append_old_updated_area (GdkSurface *surface,
-                                     cairo_region_t *region)
-{
-  if (surface->old_updated_area[1])
-    cairo_region_destroy (surface->old_updated_area[1]);
-  surface->old_updated_area[1] = surface->old_updated_area[0];
-  surface->old_updated_area[0] = cairo_region_reference (region);
-}
-
 void
 _gdk_surface_update_size (GdkSurface *surface)
 {
@@ -627,7 +602,6 @@ _gdk_surface_update_size (GdkSurface *surface)
   for (l = surface->draw_contexts; l; l = l->next)
     gdk_draw_context_surface_resized (l->data);
 
-  gdk_surface_clear_old_updated_area (surface);
   recompute_visible_regions (surface, FALSE);
 }
 
@@ -2120,8 +2094,6 @@ gdk_surface_process_updates_internal (GdkSurface *surface)
 
           gdk_surface_process_updates_recurse (surface, expose_region);
 
-          gdk_surface_append_old_updated_area (surface, surface->active_update_area);
-
           cairo_region_destroy (expose_region);
         }
 
@@ -3035,7 +3007,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS
       impl_class->hide (surface);
     }
 
-  gdk_surface_clear_old_updated_area (surface);
   recompute_visible_regions (surface, FALSE);
 
   if (was_mapped && !gdk_surface_has_impl (surface))
@@ -3093,7 +3064,6 @@ gdk_surface_withdraw (GdkSurface *surface)
         gdk_gl_context_clear_current ();
 
       recompute_visible_regions (surface, FALSE);
-      gdk_surface_clear_old_updated_area (surface);
     }
 }
 
index 700baa02d658ac021f1fa74c2047671c87fdade5..3db9db5ac491cf0bb6e47b88e71c53c0e69ae787 100644 (file)
@@ -184,16 +184,16 @@ gdk_wayland_gl_context_get_damage (GdkGLContext *context)
 
       if (buffer_age == 2)
         {
-          if (surface->old_updated_area[0])
-            return cairo_region_copy (surface->old_updated_area[0]);
+          if (context->old_updated_area[0])
+            return cairo_region_copy (context->old_updated_area[0]);
         }
       else if (buffer_age == 3)
         {
-          if (surface->old_updated_area[0] &&
-              surface->old_updated_area[1])
+          if (context->old_updated_area[0] &&
+              context->old_updated_area[1])
             {
-              cairo_region_t *damage = cairo_region_copy (surface->old_updated_area[0]);
-              cairo_region_union (damage, surface->old_updated_area[1]);
+              cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
+              cairo_region_union (damage, context->old_updated_area[1]);
               return damage;
             }
         }
index 8eca015b1c4b40033a1fa1100b47174bdbdbced7..dc8948331159a2741a450d867a93a708b48dec4e 100644 (file)
@@ -196,7 +196,6 @@ gdk_x11_gl_context_get_damage (GdkGLContext *context)
   GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
   Display *dpy = gdk_x11_display_get_xdisplay (display);
-  GdkSurface *surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context));
   unsigned int buffer_age = 0;
 
   if (display_x11->has_glx_buffer_age)
@@ -215,16 +214,16 @@ gdk_x11_gl_context_get_damage (GdkGLContext *context)
 
       if (buffer_age == 2)
         {
-          if (surface->old_updated_area[0])
-            return cairo_region_copy (surface->old_updated_area[0]);
+          if (context->old_updated_area[0])
+            return cairo_region_copy (context->old_updated_area[0]);
         }
       else if (buffer_age == 3)
         {
-          if (surface->old_updated_area[0] &&
-              surface->old_updated_area[1])
+          if (context->old_updated_area[0] &&
+              context->old_updated_area[1])
             {
-              cairo_region_t *damage = cairo_region_copy (surface->old_updated_area[0]);
-              cairo_region_union (damage, surface->old_updated_area[1]);
+              cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
+              cairo_region_union (damage, context->old_updated_area[1]);
               return damage;
             }
         }